package stu.day25_day32.day25.day3;
import stu.day25_day32.day25.all.*;
public class hw1 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        return isSum(root,0,targetSum);
    }

    public boolean isSum(TreeNode node,int sum,int targetSum){
        if(node==null){
            return false;
        }
        sum += node.val;
        if(sum==targetSum&&node.left==null&&node.right==null){
            return true;
        }
        return isSum(node.left,sum,targetSum) || isSum(node.right,sum,targetSum);
    }



    public int sumOfLeftLeaves(TreeNode root) {
        if(root==null){
            return 0;
        }
        if(root.left!=null&&root.left.left==null&&root.left.right==null){
            return root.val+sumOfLeftLeaves(root.right);
        }
        return sumOfLeftLeaves(root.left)+sumOfLeftLeaves(root.right);
    }







}
